#!/bin/bash

>/var/log/monitor_ftp.log
server_ftp=192.168.0.36
flag=1
#judge the ftp server is down or up
while :
do
	if nc -z 192.168.0.36 21 
	then
		echo "$server_ftp is running"
		if ((flag==1))
		then
			echo -e "`date +'%F %T'`\t$server_ftp is up" >>/var/log/monitor_ftp.log
			flag=0
		fi
	else
		echo -e "\e[31mwarning!!server_ftp is down\e[0m"
		if ((flag==0))
		then
			echo -e "`date +'%F %T'`\t$server_ftp is down" >>/var/log/monitor_ftp.log
			flag=1	
		fi
	sleep 1
	fi
done
